<template>
	<!--新增界面-->
	<el-dialog v-loading.fullscreen.lock="loading" element-loading-text="处理中......" title="新增险类" :visible.sync="dialogVisible" size="small" :close-on-click-modal="false" :close-on-press-escape="false" :before-close="off" :top="dialog_margin_top">
		  <el-form label-width="150px" >
		  <el-row :span="24">
		  	<el-col :span="12">
		  		<el-form-item label="险类代码" required>
					<el-input v-model="formData.classcode" :maxlength="2" size="small" @keyup.native="checkCode()"></el-input>
					<span v-show="warning" style="color:red; font-size:12px">该险类代码已存在！</span>
				</el-form-item>
				<el-form-item label="险类中文名称">
					<el-input v-model="formData.classname"size="small"></el-input>
				</el-form-item>
				<el-form-item label="险类英文名称">
					<el-input v-model="formData.classename"size="small"></el-input>
				</el-form-item>
				<el-form-item label="ACCCODE">
					<el-input v-model="formData.acccode" :maxlength="6" size="small"></el-input>
				</el-form-item>
		  	</el-col>
		  	<el-col :span="12">
				<el-form-item label="险类类别">
					<el-input v-model="formData.riskcategory" :maxlength="1" size="small"></el-input>
				</el-form-item>
				<el-form-item label="是否组合险">
					<el-select v-model="formData.compositeflag" placeholder="是否组合险" size="small">
							<el-option v-for="item in compositeOptions" :key="item.value" :label="item.value + '-'+ item.label" :value="item.value"></el-option>
						</el-select>
				</el-form-item>
				<el-form-item label="有效标识" required>
					<el-select v-model="formData.validstatus" size="small">
						<el-option v-for="item in validOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-form-item>
		  	</el-col>
		  </el-row>
		</el-form>
		  <span slot="footer" class="dialog-footer">
			   <el-button @click="off">取 消</el-button>
			   <el-button type="warning" @click="add">保存</el-button>
		  </span>
	</el-dialog>
</template>

<script>

import ClassAPI from "../../../../js/production/class/classAPI"
import Validations from "../../../../js/production/validations"

  export default {
	data() {
		return {
			dialog_margin_top: '5%',
			dialogVisible: true,
			formData: {
			        classcode : '',
			        classname : '',
			        classename : '',
			        acccode : '',
		                    validstatus: '1',
		                    riskcategory : '',
		                    compositeflag : '0',
			},
			validOptions: [
				{label : '1-有效',value: '1'},
				{label : '0-无效',value: '0'}
			],
			compositeOptions: [
				{label : '是',value: '1'},
				{label : '否',value: '0'}
			],
			loading :false,
			warning : false,
		}
	},
	mounted() {
		
	},
	methods: {
		add() {
			if(this.formData.classcode.length != 2) {
				this.$message({type: 'error',message: '险别代码必须为2位数字，请重新输入！'});
			}else if(this.warning) {
				this.$message({type: 'error',message: '险别代码已被使用，请重新输入！'});
			} else {
				ClassAPI.add(this);
			}
		},
		off() {
			this.$parent.showAddDialog = false;
		},
		checkCode() {
			this.formData.classcode = this.formData.classcode.replace(/[^\d]/g,""); //只能输入数字
			if('undefined' != typeof(this.formData.classcode) && '' != this.formData.classcode && this.formData.classcode.length == 2) {
				ClassAPI.checkClassCodeUsed(this);
			}
		}
	}
  }
</script>